package com.twu.biblioteca;

import java.io.IOException;

public class CheckOuter implements LibraryAction {

    private Library library;
    private String ACTION_NAME = "2 - Checkout A Book";
    private IOManager ioManager;

    public CheckOuter(Library library, IOManager ioManager){
        this.library = library;
        this.ioManager = ioManager;
    }

    @Override
    public void performAction() {
        ioManager.print("What book would you like to check out?");
        String title = "";
        try {
            title = ioManager.getUserInput();
        } catch(IOException ex) {
            ioManager.print("Error reading book title.");
        }

        LibraryBook book = library.findBook(title);
        book.tryCheckOut();
    }

    @Override
    public String toString() {
        return ACTION_NAME;
    }

}
